package com.laxcen.controller2;

import com.github.pagehelper.PageInfo;
import com.laxcen.smoke.dto.req.CommonOneIdReq;
import com.laxcen.smoke.dto.req.OperateTabSelectReq;
import com.laxcen.smoke.dto.req.RoleFlagPageReq;
import com.laxcen.smoke.dto.res.OperaterecordExtraRes;
import com.laxcen.smoke.service.OperationService;
import com.laxcen.smoke.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Api(tags = "操作记录")
@RestController
@RequestMapping("/operation")
public class OperationController {

    @Autowired
    private OperationService operationService;

//    @ApiOperation(value = "添加操作记录",notes =
//            "请求信息： \n" +
//                    "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
//                    "&emsp; boxno &nbsp; : &nbsp; 格子编号 \n" +
//                    "&emsp; opname &nbsp; : &nbsp; 操作人  \n" +
//                    "&emsp; optype &nbsp; : &nbsp; 操作类型 0取货 1配送 \n" +
//                    "&emsp; video &nbsp; : &nbsp; 监控视频 \n" +
//                    "&emsp; orderno &nbsp; : &nbsp; 关联订单 \n" +
//                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
//                    "返回码： \n" +
//                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
//                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
//    @PostMapping(value = "/insert")
//    public Response insert(@RequestBody OperationInsertReq operationInsertReq){
//        return operationService.insert(operationInsertReq.getSmartno(),operationInsertReq.getBoxno(),operationInsertReq.getOpname(),operationInsertReq.getOptype(),operationInsertReq.getVideo(),operationInsertReq.getOrderno(),operationInsertReq.getRemark());
//    }

    @ApiOperation(value = "获取操作记录列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限 (0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
            "返回信息： \n" +
            "&emsp; id &nbsp; : &nbsp; id \n" +
            "&emsp; opid &nbsp; : &nbsp; 操作人id \n" +
            "&emsp; optime &nbsp; : &nbsp; 操作时间 \n" +
            "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
            "&emsp; devicename &nbsp; : &nbsp; 柜子名称 \n" +
                    "&emsp; boxno &nbsp; : &nbsp; 格子编号 \n" +
                    "&emsp; optype &nbsp; : &nbsp; 操作类型 0存入 1取出 2远程开门 3异常处理\n" +
                    "&emsp; videoleft &nbsp; : &nbsp; 监控视频(左摄像头) \n" +
                    "&emsp; videoright &nbsp; : &nbsp; 监控视频(右摄像头) \n" +
                    "&emsp; orderno &nbsp; : &nbsp; 关联订单 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @RequiresPermissions("operations")
    @PostMapping(value = "/getalllist")
    public Response<PageInfo<OperaterecordExtraRes>> getAllList(@RequestBody RoleFlagPageReq roleFlagPageReq){
       if (roleFlagPageReq.getPageNo()==null){
           roleFlagPageReq.setPageNo(1);
       }
        if (roleFlagPageReq.getPageSize()==null){
            roleFlagPageReq.setPageSize(10);
        }
        if (roleFlagPageReq.getPageNo()==null&&roleFlagPageReq.getPageSize()==null){
            roleFlagPageReq.setPageNo(1);
            roleFlagPageReq.setPageSize(10);
        }
        return operationService.getAllList(roleFlagPageReq.getPageNo(),roleFlagPageReq.getPageSize(),roleFlagPageReq.getRoleflag(),roleFlagPageReq.getProvince(),roleFlagPageReq.getCity(),roleFlagPageReq.getArea());
    }

    @ApiOperation(value = "操作记录导航栏搜索",notes =
            "请求信息： \n" +
                    "&emsp; orderno &nbsp; : &nbsp; 订单号 \n" +
                    "&emsp; starttime &nbsp; : &nbsp; 时间左区间 \n" +
                    "&emsp; endtime &nbsp; : &nbsp; 时间右区间 \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限 (0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; opid &nbsp; : &nbsp; 操作人id \n" +
                    "&emsp; optime &nbsp; : &nbsp; 操作时间 \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
                    "&emsp; boxno &nbsp; : &nbsp; 格子编号 \n" +
                    "&emsp; optype &nbsp; : &nbsp; 操作类型 0存入 1取出 2远程开门 3异常处理\n" +
                    "&emsp; videoleft &nbsp; : &nbsp; 监控视频(左摄像头) \n" +
                    "&emsp; videoright &nbsp; : &nbsp; 监控视频(右摄像头) \n" +
                    "&emsp; orderno &nbsp; : &nbsp; 关联订单 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/gettablist")
    @RequiresPermissions("operation:get")
    public Response<PageInfo<OperaterecordExtraRes>> getTabList(@RequestBody OperateTabSelectReq operateTabSelectReq) throws ParseException {
        if (operateTabSelectReq.getPageNo()==null){
            operateTabSelectReq.setPageNo(1);
        }
        if (operateTabSelectReq.getPageSize()==null){
            operateTabSelectReq.setPageSize(10);
        }
        if (operateTabSelectReq.getPageNo()==null&&operateTabSelectReq.getPageSize()==null){
            operateTabSelectReq.setPageNo(1);
            operateTabSelectReq.setPageSize(10);
        }
        return operationService.getTabList(operateTabSelectReq.getOrderno(),operateTabSelectReq.getStarttime(),operateTabSelectReq.getEndtime(),operateTabSelectReq.getRoleflag(),operateTabSelectReq.getProvince(),operateTabSelectReq.getCity(),operateTabSelectReq.getArea(),operateTabSelectReq.getPageNo(),operateTabSelectReq.getPageSize());
    }


    @ApiOperation(value = "获取某一个操作记录详情",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; opid &nbsp; : &nbsp; 操作人id \n" +
                    "&emsp; optime &nbsp; : &nbsp; 操作时间 \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 柜子编号 \n" +
                    "&emsp; devicename &nbsp; : &nbsp; 柜子名称 \n" +
                    "&emsp; boxno &nbsp; : &nbsp; 格子编号 \n" +
                    "&emsp; optype &nbsp; : &nbsp; 操作类型 0存入 1取出 2远程开门 3异常处理\n" +
                    "&emsp; videoleft &nbsp; : &nbsp; 监控视频(左摄像头) \n" +
                    "&emsp; videoright &nbsp; : &nbsp; 监控视频(右摄像头) \n" +
                    "&emsp; orderno &nbsp; : &nbsp; 关联订单 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getone")
    @RequiresPermissions("operation:getone")
    public Response<OperaterecordExtraRes> getOne(@RequestBody CommonOneIdReq commonOneIdReq){

        return operationService.getOne(commonOneIdReq.getId());
    }

//    @ApiOperation(value = "删除某一个操作记录",notes =
//            "返回信息： \n" +
//                    "&emsp; id &nbsp; : &nbsp; id \n" +
//                    "返回码： \n" +
//                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
//                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
//    @PostMapping(value = "/delete")
//    public Response delete(@RequestBody CommonOneIdReq commonOneIdReq){
//        return operationService.delete(commonOneIdReq.getId());
//    }


}
